package odooapi

import (
	"fmt"
	"log"
)

func Template_crud() {
	client, err := ClientConnect("testing", "huang19920410@126.com", "113246")
	if err != nil {
		log.Fatal("Error connecting to Odoo")
		return
	}

	//read sales order
	sales, err := client.SearchRead(
		"sale.order",
		List{
			List{"user_id", "=", 2},
		},
		[]string{"name", "create_date"},
	)
	fmt.Println(sales)
	if err != nil {
		fmt.Println(err)
	}

	// update product
	var ids = []int{22}
	var writeobj = make(map[string]interface{})
	writeobj["list_price"] = 2.2
	client.Write(
		"product.template",
		ids,
		writeobj,
	)

	//delete product
	var delids = []int{35}
	client.Delete(
		"product.template",
		delids,
	)

	// create product
	var creadobj = make(map[string]interface{})
	creadobj["name"] = "woshidashabi34"
	creadobj["barcode"] = "wulaaa"
	id, err := client.Create(
		"product.template",
		creadobj,
	)
	fmt.Println(err)
	fmt.Println(id)
}
